# -*- encoding:utf-8 -*-

class TaobaoResponse(object):
    """调用Top的API返回的response 
            ErrorCode错误码 
            body 响应的body部分 
            redirectUrl 绑定用户所需重定向URL
    """

    taobaoObject = []

    def __init__(self, body=None, errorCode=None, msg=None, 
                 redirectUrl=None, requestUrl=None,
                 requestBody=None, requestParameters=None):

        self.body           = body
        self.errorCode      = errorCode
        self.msg            = msg
        self.redirectUrl    = redirectUrl
        self.requestUrl     = requestUrl
        self.requestBody    = requestBody
        self.requestParameters = requestParameters

    def getErrorCode(self):
        return self.errorCode

    def setErrorCode(self, errorCode):
        self.errorCode = errorCode

    def getMsg(self):
        return self.msg

    def setMsg(self, msg):
        self.msg = msg

    def isSucsess(self):
        return "" == self.errorCode

    def isRedirect(self):
        return self.redirectUrl != ''

    def getRedirectUrl(self, target=''):
        if target == "":
            return self.redirectUrl
        else:
            return self.redirectUrl + "&sip_redirecturl=" + target

    def setRedirectUrl(self, redirectUrl):
        self.redirectUrl = redirectUrl

    def getBody(self):
        return self.body

    def setBody(self, body):
        self.body = body
        
    def getRequestUrl(self):
        return self.getRequestUrl

    def setRequestUrl(self, requestUrl):
        self.requestUrl = requestUrl

    def getRequestBody(self):
        return self.requestBody

    def setRequestBody(self, requestBody):
        self.requestBody = requestBody

    def getRequestParameters(self):
        return self.requestParameters

    def setRequestParameters(self, requestParameters):
        self.requestParameters = requestParameters

    def setTaobaoObject(self, object):
        self.taobaoObject = object
        
    def getTaobaoObject(self):
        return self.taobaoObject
    
    def getFirst(self):
        if len(self.taobaoObject) > 0:
            return self.taobaoObject[0]
        else:
            return None

class TaobaoListResponse(TaobaoResponse):
    """Taobao Response Object List"""

    def __init__(self, rsp=None):
        """  
            @rsp: TaobaoResponse
        """
        self.totalResults = int()
        if rsp:
            super(TaobaoListResponse, self).__init__(rsp.body, 
              rsp.errorCode, rsp.msg, rsp.redirectUrl, 
              rsp.requestUrl, rsp.requestBody, rsp.requestParameters)
        else:
            super(TaobaoListResponse, self).__init__()
    
    def getTotalResults(self):
        return self.totalResults
 
    def setTotalResults(self, totalResults):
        self.totalResults = totalResults

